package com.jz.netthings.application.stockManage.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.jz.netthings.application.stockManage.bean.ConsumablesStorage;
import com.jz.netthings.application.stockManage.bean.ConsumablesTemplate;
import com.jz.netthings.application.stockManage.service.ConsumablesStorageService;
import com.jz.netthings.exception.AdscmSystemException;
import com.jz.netthings.support.SimpleCoreResponse;
import com.jz.netthings.utils.AdscmBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * <p>
 * 耗材入库信息 前端控制器
 * </p>
 *
 * @author yangyunyun
 * @since 2019-07-19
 */
@RestController
@RequestMapping("/adscm/application/consumablesStorage")
public class ConsumablesStorageController {

    @Autowired
    ConsumablesStorageService consumablesStorageService;

    /**
     * 新增耗材入库信息
     * @param consumablesStorage
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/insertStorage")
    public SimpleCoreResponse insertStorage(@RequestBody ConsumablesStorage consumablesStorage) throws AdscmSystemException {

        consumablesStorage.setStorageDate(new Date());
        consumablesStorageService.insert(consumablesStorage);
        return new SimpleCoreResponse("200","新增成功",null);
    }

    /**
     * 条件查询入库信息
     * @param beginDate 入库的开始日期
     * @param endDate 入库的结束日期
     * @param supplierId 供应商ID
     * @param orderNum 入库单号
     * @param templateId 模板ID
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/selectByCondition")
    public SimpleCoreResponse selectByCondition(String beginDate,String endDate,Integer supplierId,String orderNum,Integer templateId) throws AdscmSystemException {

        Wrapper<ConsumablesStorage> wrapper = new EntityWrapper<>();
        if (AdscmBaseUtils.getInstance().isNotEmpty(beginDate,null)){
            wrapper.ge("storageDate",beginDate);
        }
        if (AdscmBaseUtils.getInstance().isNotEmpty(endDate,null)){
            wrapper.le("storageDate",endDate);
        }
        if (supplierId != null && supplierId > 0){
            wrapper.eq("supplierId",supplierId);
        }
        if (templateId != null && templateId > 0){
            wrapper.eq("templateId",templateId);
        }
        if (AdscmBaseUtils.getInstance().isNotEmpty(orderNum,null)){
            wrapper.eq("orderNum",orderNum);
        }
        return new SimpleCoreResponse("200","查询成功",consumablesStorageService.selectList(wrapper));
    }

}

